Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

function udiab() {
    this.wrappedJSObject = this;
}

udiab.prototype = {
    classDescription: "udiab cao baidu",
    classID:          Components.ID("{9C330154-1E65-3E7A-A4FF-08DE275D6BBB}"),
    contractID:       "@liulanqi.org/udiab;1",
    QueryInterface: XPCOMUtils.generateQI(),
    onPageLoad: function(aEvent) {
        var doc = aEvent.originalTarget;
        if(doc.location.href.search("baidu.com") < 0) {
            return;
        }

        var max_find_parent=8;
        var as=doc.getElementsByTagName("a");
        while (true) {
            var node;
            var br_node;
            b=false;
            try {
                for (i in as) {
                    if (as[i].id.search('dfs')>-1) {
                        node=doc.getElementById('b'+as[i].id)
                    } else if (as[i].href.search('baidu.php')>-1) {
                        node=as[i].parentNode;
                        for (u=0;u<max_find_parent;u++) {
                            if (node.nodeName.toLowerCase()=='table') {
                                break;
                            }
                            node=node.parentNode;
                        }
                        if (u>=max_find_parent) {
                            continue;
                        }
                    } else if (as[i].href.search('click.php')>-1 
                        && as[i].href.search('plrcv.baidu.com')<0) {
                        node=as[i];
                    } else {
                        continue;
                    }

                    try {
                        br_node=node.nextSibling;
                        if (br_node.nodeName.toLowerCase()=='br') {
                            br_node.parentNode.removeChild(br_node);
                        }
                    } catch (e2) {}
                    node.parentNode.removeChild(node);
                    b=true;
                    break;

                }
            } catch (e) {
                dump(e);
            }

            if (!b) {
                break;
            }
        }
    }
};
var components = [udiab];
function NSGetModule(compMgr, fileSpec) {
  return XPCOMUtils.generateModule(components);
}
